class Solution {
    public int[] twoSum(int[] nums, int target) {
        //错误：如[3,4,5] 6,6-3=3,但数组中只有一个3，所以得先输入后比较，唯一性
        // Map<Integer,Integer> m = new HashMap<Integer,Integer>();
        // for (int i=0;i<nums.length;++i){
        //     m.put(nums[i],i);
        // }
        // System.out.println("答案"+ m);
        // for (int i=0;i<nums.length;++i){
        //     int num = target-nums[i];
        //     System.out.println("答案"+ m.containsKey(num));
        //     if(m.containsKey(num)){
        //         return new int[]{i, m.get(num) };
        //     }
        // }
        // throw new RuntimeException("no answer!");
         Map<Integer, Integer> m = new HashMap<Integer,Integer>();
         for(int i = 0;i < nums.length;++i) {
            int num = target - nums[i];
            System.out.println("答案"+ m.containsKey(num));
            if(m.containsKey(num))
                return new int[]{m.get(num), i };
            m.put(nums[i], i);
         }
         throw new RuntimeException("no answer!");
    }
}

